package com.yc.sssmpg.controller;

import java.util.List;

import com.yc.framework.utils.ExcelUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;

import com.yc.sssmpg.service.IProductService;


import org.springframework.web.bind.annotation.RestController;
import com.yc.framework.baseClass.BaseController;
//import com.yc.framework.baseClass.ServiceFacade;
import com.yc.framework.baseClass.R;
import com.yc.sssmpg.entity.Product;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 6521825@qq.com
 * @since 2022-11-23
 */
@RestController
@RequestMapping("/sys/product")
public class ProductController extends BaseController {

    @Autowired
    //private IProductService t_productService;
    private IProductService service;

    /**
     * 根据条件分页查询Product
     *
     * @param model 实体对象
     * @return 查询列表
     */
    @PostMapping("/list")
    public R list(@RequestBody Product model) {
        return service.list(model);

    }

    /**
     * 根据主键查询单个对象
     *
     * @return 成功或失败
     */
    @GetMapping("/getById/{id}")
    public R getById(@PathVariable String id) {
        return service.getModelById(id);
    }

    /**
     * 新增实体对象
     *
     * @param model 实体对象
     * @return 新增是否成功
     */
    @PostMapping("/save")
    public R save(@RequestBody Product model) {
        return service.saveModel(model);

    }

    /**
     * 批量新增实体对象
     *
     * @param modelList 实体对象列表
     * @return 新增是否成功
     */
    @PostMapping("/saveBatch")
    public R saveBatch(@RequestBody List<Product> modelList) {
        return service.saveModelBatch(modelList);

    }

    /**
     * 根据主键删除实体
     *
     * @return 删除是否成功
     */
    @DeleteMapping("/removeById/{id}")
    public R removeById(@PathVariable String id) {
        return service.removeModelById(id);
    }

    /**
     * 根据主键列表删除实体
     *
     * @param idList 实体主键
     * @return 删除是否成功

     @DeleteMapping("/removeByIdList") public R removeByIdList(@RequestBody List<Product> idList) {
     return service.removeModelByIdList(idList);

     }
     */
    /**
     * 根据主键修改实体
     *
     * @param model 等待修改的对象
     * @return 修改是否成功
     */
    @PutMapping("/updateById")
    public R updateModelById(@RequestBody Product model) {
        return service.updateModelById(model);

    }

    /**
     * 根据主键列表修改实体列表
     *
     * @param modelList 等待修改的对象列表
     * @return 修改是否成功
     */
    @PostMapping("/updateByIdBatch")
    public R updateModelByIdBatch(@RequestBody List<Product> modelList) {
        return service.updateModelByIdBatch(modelList);

    }

    /**
     * 根据多主键列表删除实体
     *
     * @return 删除是否成功
     */
    @DeleteMapping("/removeByIds/{ids}")
    public R removeByIdList(@PathVariable String ids) {
        return service.removeModelByIds(ids);

    }

    @PostMapping("/findByProductNo/{productNo}")
    public R findByProductNo(@PathVariable Integer productNo) {
        return service.findByProductNo(productNo);
    }

    @Autowired
    ExcelUtils excelUtils;

    @PostMapping("/import")
    public R importProduct(MultipartFile file) {
        return excelUtils.importModel(file, service, Product.class);
    }

    @GetMapping("/export")
    public void exportProduct(HttpServletResponse resp) {
        excelUtils.exportModel(Product.class, resp, service.list());
    }
}
